package com.tanhua.dubbo.server.vo;

import com.tanhua.dubbo.server.pojo.UserLocation;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.bson.types.ObjectId;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @description:
 * @author: Administrator
 * @date: Created in 2021/2/28 16:57
 * @version: 0.0.1
 * @modified By:
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class UserLocationVo implements Serializable {
    private static final long serialVersionUID = 4133419501260037769L;
    private String id;
    private Long userId; //用户id
    private Double longitude;//经度
    private Double latitude;//纬度
    private String address; //位置描述
    private Long created; //创建时间
    private Long updated; //更新时间
    private Long lastUpdated; //上次更新时间

    public static final UserLocationVo format(UserLocation userLocation){
        UserLocationVo userLocationVo=new UserLocationVo();
        userLocationVo.setId(userLocation.getId().toHexString());
        userLocationVo.setAddress(userLocation.getAddress());
        userLocationVo.setCreated(userLocation.getCreated());
        userLocationVo.setLastUpdated(userLocation.getLastUpdated());
        userLocationVo.setUpdated(userLocation.getUpdated());
        userLocationVo.setUserId(userLocation.getUserId());
        userLocationVo.setLongitude(userLocation.getLocation().getX());
        userLocationVo.setLatitude(userLocation.getLocation().getY());
        return userLocationVo;
    }

    public static final List<UserLocationVo> formatToList(List<UserLocation>userLocationList){
        List<UserLocationVo>userLocationVos=new ArrayList<>();
        for (UserLocation userLocation : userLocationList) {
            userLocationVos.add(format(userLocation));
        }
        return userLocationVos;
    }
}
